
#ifndef PROJECTZ_NUSER_NCOMMAND_CS_REQ_DESTROY_ITEM_H_
#define PROJECTZ_NUSER_NCOMMAND_CS_REQ_DESTROY_ITEM_H_

#include "../../engine.h"

#include "../../User.h"
#include "../../NLogic/Item.h"
#include "../../NLogic/Bag.h"

namespace ProjectZ { namespace NCommand { namespace NWorld {

class CS_REQ_DESTROY_ITEM
{
public:
	static void OnExecute(User * pUser, ::Network::Packet * pPacket)
	{
		PREPARE_PACKET;

		uint8_t		bagType = 0;
		uint64_t	itemSeq	= 0;

		pPacket->ParseMsg("%c", &bagType);
		pPacket->ParseMsg("%8d", &itemSeq);

		NLogic::Bag * pBag	= pUser->GetBag(static_cast<INVEN_BAG_TYPE>(bagType));

		if (pBag == NULL)
		{
			SendPacket(pUser, ACK_UNKNOWN_ERROR, 0);
			return;
		}

		NLogic::Item * pItem	= pBag->PopItem(itemSeq);

		if (pItem == NULL)
		{
			SendPacket(pUser, ACK_UNKNOWN_ERROR, 0);
			return;
		}

		if (true == pItem->IsEquip())
		{
			SendPacket(pUser, ACK_UNKNOWN_ERROR, 0);
			return;
		}

		pItem->DeleteDatabaseItemInfo(NLogic::Item::ItemStatus::EM_ITEM_STATUS_DESTROY);

		SendPacket(pUser, ACK_OK, itemSeq);
	}

	static void SendPacket(User * pUser, int res, uint64_t itemSeq)
	{
		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();

		pAck->MsgCat("%2d", res);
		pAck->MsgCat("%8d", itemSeq);
		pAck->MakePacket(CMD_SC_REQ_DESTROY_ITEM);

		pUser->Send(pAck);
	}
};

} /*NWorld*/ } /*NCommand*/ } /*ProjectZ*/


#endif /* PROJECTZ_NUSER_NCOMMAND_CS_REQ_DESTROY_ITEM_H_ */
